
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/23/2012 12:51:44
-- Generated from EDMX file: D:\GrooveWorkspaces\Programming Workspace\AuditSolution\auditmvc\auditmvc\AuditModel\AuditModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [AuditDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[AnnualEvents]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AnnualEvents];
GO
IF OBJECT_ID(N'[dbo].[Archives]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Archives];
GO
IF OBJECT_ID(N'[dbo].[Counties]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Counties];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'AnnualEvents'
CREATE TABLE [dbo].[AnnualEvents] (
    [ID] nvarchar(50)  NOT NULL,
    [Title] nvarchar(50)  NULL,
    [Year] int  NULL,
    [Status] nvarchar(50)  NULL
);
GO

-- Creating table 'Counties'
CREATE TABLE [dbo].[Counties] (
    [Name] nvarchar(50)  NOT NULL,
    [Code] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Subjects'
CREATE TABLE [dbo].[Subjects] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Archives'
CREATE TABLE [dbo].[Archives] (
    [ID] nvarchar(50)  NOT NULL,
    [AnnualEventID] nvarchar(50)  NULL,
    [CountyID] nvarchar(50)  NULL,
    [SubjectID] nvarchar(50)  NULL,
    [TeacherID] nvarchar(50)  NULL,
    [SchoolComment] nvarchar(500)  NULL,
    [CountyComment] nvarchar(500)  NULL,
    [CountyEBComment] nvarchar(500)  NULL,
    [Attachment1LessonPlan] nvarchar(250)  NULL,
    [Attachment2Explanation] nvarchar(250)  NULL,
    [ClassDate] datetime  NULL,
    [ClassTime] datetime  NULL,
    [AnnualEvent_ID] nvarchar(50)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'AnnualEvents'
ALTER TABLE [dbo].[AnnualEvents]
ADD CONSTRAINT [PK_AnnualEvents]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Code] in table 'Counties'
ALTER TABLE [dbo].[Counties]
ADD CONSTRAINT [PK_Counties]
    PRIMARY KEY CLUSTERED ([Code] ASC);
GO

-- Creating primary key on [Id] in table 'Subjects'
ALTER TABLE [dbo].[Subjects]
ADD CONSTRAINT [PK_Subjects]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [ID] in table 'Archives'
ALTER TABLE [dbo].[Archives]
ADD CONSTRAINT [PK_Archives]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [AnnualEvent_ID] in table 'Archives'
ALTER TABLE [dbo].[Archives]
ADD CONSTRAINT [FK_AnnualEventArchive]
    FOREIGN KEY ([AnnualEvent_ID])
    REFERENCES [dbo].[AnnualEvents]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnnualEventArchive'
CREATE INDEX [IX_FK_AnnualEventArchive]
ON [dbo].[Archives]
    ([AnnualEvent_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------